/*
ID: icerupt1
PROG: gift1
LANG: C++11
*/

#include <fstream>
#include <unordered_map>
#include <vector>
#include <string>
using namespace std;

int n;

int main()
{
	ifstream fin ("gift1.in");
	ofstream fout ("gift1.out");

	vector<string> list;
	fin >> n;
	unordered_map<string, int> m;
	unordered_map<string, int> initial_amount;
	for (int i = 0; i < n; i++) {
		string name;
		fin >> name;
		m[name] = 0;
		list.push_back(name);
	}

	for (int i = 0; i < n; i++) {
		string name;
		fin >> name;
		int initial, num;
		fin >> initial >> num;
		initial_amount[name] = initial;
		if (num == 0) {
			m[name] += initial;
			continue;
		} else
			m[name] += initial % num;
		for (int j = 0, delta = initial / num; j < num; j++) {
			fin >> name;
			m[name] += delta;
		}
	}

	for (auto i : list)
		fout << i << " " << m[i] - initial_amount[i] << endl;
}
